package com.gaogzhen.algorithm.leetCode.daily;

/**
 * 题目：2383. 赢得比赛需要的最少训练时长
 * 地址：https://leetcode.cn/problems/minimum-hours-of-training-to-win-a-competition/
 * @author: Administrator
 * @createTime: 2023/03/06 21:47
 */
public class D20230313 {
    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int len = energy.length;
        int t = 0;
        for (int i = 0; i < len; i++) {
            if (initialEnergy - energy[i] < 1) {
                t += energy[i] - initialEnergy + 1;
                initialEnergy = 1;
            } else {
                initialEnergy -= energy[i];
            }
            if (initialExperience - experience[i] < 1) {
                t += experience[i] - initialExperience + 1;
                initialExperience = experience[i] + 1;
            }
            initialExperience += experience[i];
        }
        return t;
    }
}
